<include file="public@storage"/>
</head>
<body>
<div class="container body-content" style="margin-top:20px;width: 100%">
    <div class="panel panel-info" style="margin-bottom: 0.5rem">
        <div class="panel-heading">仓库管理</div>
        <div class="panel-body">
            <div class="row">
                <div class="col-sm-12">

                    <div id="toolbar" class="btn-group">
                        <button class="btn btn-info" style="margin-left: 5px;width: 8rem" onclick="add()">
                            添加仓库
                        </button>
                    </div>
                    <table id="table"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>

    $(function () {
        init();
    });

    function init() {
        var url = "{:url('storage/Storage/getStorage')}";
        var columns = [
            {
                title: '序号',
                width: 50,
                align: "center",
                valign: 'middle',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },
            {
                title: 'uuid',
                field: 'uuid',
                visible: false
            },
            {
                title: '仓库名',
                field: 'name',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '地址',
                field: 'address',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: 'IP',
                field: 'ip_address',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '电话',
                field: 'phone',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '归属厂商',
                field: 'company_name',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '操作',
                field: 'uuid',
                width: 200,
                align: "center",
                valign: 'middle',
                formatter: function (value, row, index) {
                    var html = '<a href="/storage/Shelf/index?storageUuid=' + row.uuid + '&history=1">货架</a>';
                    html += '&nbsp&nbsp|&nbsp&nbsp';
                    html += '<a href="{:url(\'storage/Storage/edit\')}?storageUuid=' + row.uuid + '">编辑</a>';
                    html += '&nbsp&nbsp|&nbsp&nbsp';
                    html += '<a onclick="del(this)" href="javascript:;" data-uuid="' + row.uuid + '" data-name="'+ row.name+'">删除</a>';
                    return html;
                }
            }
        ];
        initTable(url, columns, 'server', InitSubTable);
    }

    InitSubTable = function (index, row, $detail) {
        var tableId = "cur_table_"+index;
        $detail.html('<table id="'+ tableId+ '"></table>').find('table');
        var storageUuid = row.uuid;
        var url = '{:url("storage/Shelf/getShelf")}?storageUuid=' + storageUuid;
        var column = [
            {
                title: '序号',
                width: 50,
                align: "center",
                valign: 'middle',
                formatter: function (value, row, index) {
                    return index + 1;
                }
            },
            {
                title: 'uuid',
                field: 'uuid',
                align: "center",
                visible: false
            },
            {
                title: '货架号',
                field: 'shelves_code',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '层数',
                field: 'floor',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '每层站位数',
                field: 'floor_count',
                align: "center",
                filter: {
                    type: 'input'
                }
            },
            {
                title: '总站位数',
                field: 'seat_count',
                align: "center",
                filter: {
                    type: 'input'
                }
            }
        ];
        initSubTable(tableId,url, column, 'server');
    };

    add = function () {
        window.open("{:url('/storage/Storage/add')}", '_self');
    };

    del = function (that) {
        var uuid = $(that).data('uuid');
        var url = "{:url('Storage/deleteStorage')}";
        var name = $(that).data('name');
        var param = {storageUuid: uuid};
        reviseTable('是否删除仓库' + name, url, param);
    }
</script>
</html>